package com.v1.video.adapter;

import java.util.ArrayList;
import java.util.List;

import com.v1.video.R;
import com.v1.video.domain.SetHead;
import com.v1.video.domain.PetitionDetailEntity.PetitionNewcmt;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
/**
 * 请愿详情适配器
 * @author wangfang
 *
 */
public class PetitionDetailAdapter extends BaseAdapter {
	
	private Context mContext;
	private LayoutInflater mLayoutInflater;
	private List<PetitionNewcmt> mLstData;
	
	public PetitionDetailAdapter(Context context) {
		this.mContext = context;
		this.mLayoutInflater = LayoutInflater.from(context);
		this.mLstData = new ArrayList<PetitionNewcmt>();
	}
	
	public List<PetitionNewcmt> getLstData() {
		return mLstData;
	}

	public void setLstData(List<PetitionNewcmt> lstData) {
		if (lstData != null && lstData.size() > 0) {
			this.mLstData = lstData;
			this.notifyDataSetChanged();
		}
	}
	
	public void setAddLstData(List<PetitionNewcmt> lstData) {
		if (lstData != null && lstData.size() > 0) {
			this.mLstData.addAll(lstData);
			this.notifyDataSetChanged();
		}
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mLstData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mLstData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Holder holder = null;
		if (convertView == null) {
			convertView = mLayoutInflater.inflate(
					R.layout.activity_petitiondetail_item, null);
			holder = new Holder();
			holder.userImg = (ImageView) convertView
					.findViewById(R.id.iv_userImg);
			holder.authImg = (ImageView) convertView
					.findViewById(R.id.iv_authImg);
			holder.name = (TextView) convertView.findViewById(R.id.tv_name);
			holder.time = (TextView) convertView.findViewById(R.id.tv_time);
			holder.content = (TextView) convertView
					.findViewById(R.id.tv_content);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		PetitionNewcmt info = this.mLstData.get(position);
		new SetHead().setHead(info.getUsr_avatar(), "", holder.userImg);
		if (info.getIsauth() == 1) {
			holder.authImg.setVisibility(View.VISIBLE);
		} else {
			holder.authImg.setVisibility(View.GONE);
		}
		if (!TextUtils.isEmpty(info.getUsr_nickname())) {
			holder.name.setText(info.getUsr_nickname());
		} else {
			holder.name.setText("");
		}
		if (!TextUtils.isEmpty(info.getWcm_date())) {
			holder.time.setText(info.getWcm_date());
		} else {
			holder.time.setText("");
		}
		if (!TextUtils.isEmpty(info.getWcm_content())) {
			holder.content.setText(info.getWcm_content());
		} else {
			holder.content.setText("");
		}
		return convertView;
	}

	private class Holder{
		public ImageView userImg;
		public ImageView authImg;
		public TextView name;
		public TextView time;
		public TextView content;
	}
}
